home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pdcurs21.zip / PORTABLE.ZIP / SCROLL.C < prev    next >
Text File  |  1992-11-21  |  2KB  |  83 lines

  1. #define        CURSES_LIBRARY  1
  2. #include <curses.h>
  3. #undef scroll
  4.  
  5. #ifndef        NDEBUG
  6. char *rcsid_scroll = "$Header: c:/curses/portable/RCS/scroll.c%v 2.0 1992/11/15 03:28:49 MH Rel $";
  7. #endif
  8.  
  9.  
  10.  
  11.  
  12.  
  13. /*man-start*********************************************************************
  14.  
  15.   scroll()     - scroll window
  16.  
  17.   X/Open Description:
  18.        The window is scrolled up one line.  THis involves moving the
  19.        lines in the window data strcture.
  20.  
  21.   PDCurses Description:
  22.        No additional functionality at this time.  Thought it might be
  23.        be nice to provide reverse scrolling, or scrolling 'n' lines
  24.        in a positive (down) or negative (up) direction in a future
  25.        release for the PC platform.
  26.  
  27.   X/Open Return Value:
  28.        The scroll() function returns OK on succes and ERR on error.
  29.  
  30.   PDCurses Errors:
  31.        It is an error to pass a NULL* window.
  32.  
  33.   Portability:
  34.        PDCurses        int scroll( WINDOW* win );
  35.        X/Open Dec '88  int scroll( WINDOW* win );
  36.        SysV Curses     int scroll( WINDOW* win );
  37.        BSD Curses      int scroll( WINDOW* win );
  38.  
  39. **man-end**********************************************************************/
  40.  
  41. int    scroll(WINDOW *win)
  42. {
  43.        int     i;
  44.        chtype* ptr;
  45.        chtype* temp;
  46. static chtype  blank;
  47.  
  48.        if (win == (WINDOW *)NULL)
  49.                return( ERR );
  50.  
  51.        blank = win->_blank | win->_attrs;
  52.  
  53.        /*
  54.         * Check if window scrolls      and cursor in region.
  55.         */
  56.        if ((!win->_scroll) ||
  57.            (win->_cury < win->_tmarg) ||
  58.            (win->_cury > win->_bmarg))
  59.        {
  60.                return( ERR );
  61.        }
  62.  
  63.        temp = win->_y[win->_tmarg];
  64.        for (i = win->_tmarg; (i < win->_bmarg); i++)
  65.        {
  66.                win->_y[i] = win->_y[i + 1];    /* re-arrange line
  67.                                                         * pointers */
  68.                win->_firstch[i] = 0;
  69.                win->_lastch[i] = win->_maxx - 1;
  70.        }
  71.  
  72.        for (ptr = temp; (ptr - temp < win->_maxx); ptr++)
  73.                *ptr = blank;                           /* make a blank line */
  74.  
  75.        win->_y[win->_bmarg] = temp;
  76.        if (win->_cury > win->_tmarg)                   /* if not on top line */
  77.                win->_cury--;                           /* cursor scrolls too */
  78.  
  79.        win->_firstch[win->_bmarg] = 0;
  80.        win->_lastch[win->_bmarg] = win->_maxx - 1;
  81.        return( OK );
  82. }
  83.